from django.shortcuts import render, get_object_or_404
from django.http import *
from django.db.models import Q
from django.core.exceptions import ObjectDoesNotExist
from django.template import RequestContext, loader
from django.contrib.auth.models import User

# Create your views here.

def home(request):
	if request.user.is_authenticated():
		me = request.facebook.graph.get_object('me')
		access_token = request.facebook.graph.access_token
		info = random.choice(INFO)
		return render(request, 'home.html', {'me':me, 'access_token':access_token, 'info':info})
	else:
		return HttpResponseForbidden('Forbidden')

def index(request):
	if request.user.is_authenticated():	
		return render(request, 'users/index.html', {"users" : User.objects.all()})
	else:
		return HttpResponseForbidden('Forbidden')

def detail(request, user_id):
	if request.user.is_authenticated():
		user = get_object_or_404(User, id=user_id)
		return render(request, 'users/detail.html', {"user" : user})
	else:
		return HttpResponseForbidden('Forbidden')
	
def list(request):
	if request.user.is_authenticated():
		return render(request, 'users/list.html', {"users" : User.objects.all()})
	else:
		return HttpResponseForbidden('Forbidden')

def export_users(request):
	if request.user.is_authenticated():
		return render(request, 'users/export.xml', {"users" : User.objects.all()})
	else:
		return HttpResponseForbidden('Forbidden')

#def update_status(request):
#	info = request.POST['info']
#	access_token = request.POST['access_token']
#	graph = facebook.GraphAPI(access_token)
#	graph.put_object("me","feed",message=info)
#	return render(request, 'all_done.hmtl')
